// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import './config/rem'
import './api/city'
import axios from 'axios'
import qs from 'qs';
import { Toast } from 'mint-ui'
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.use(MintUI, qs)
/* eslint-disable no-new */
Vue.prototype.axios = axios
// 添加一个返回拦截器
axios.interceptors.response.use(function (response) {
  // 对返回的数据进行一些处理
  return response;
}, function (err) {
  // 对返回的错误进行一些处理
  if (err.response.config.url.includes('/api/Product/IsFavourite')) {
    // 过滤商品详情页的登录跳转进行处理
    localStorage.removeItem('lut');
  } else if (err.response.config.url.includes('/api/ShoppingCar/UserShoppingCar')) {
    // 过滤购物车的登录跳转进行处理
    localStorage.removeItem('lut');
  } else if (err.response.config.url.includes('/api/CM_Information/GetInfoCount')) {
    // 过滤登录跳转进行处理
    localStorage.removeItem('lut');
  } else if (err.response.config.url.includes('/api/Product/GetUserViewProduct')) {
    // 过滤获取用户喜欢的登录跳转进行处理
    localStorage.removeItem('lut');
  } else if (err.response.status === 401) {
    let instance = Toast('还未登录，请先登录');
    setTimeout(() => {
      instance.close();
      router.replace({
        path: '/login/',
        query: { redirect: router.currentRoute.fullPath }
      })
    }, 1500);
  } else {
    Toast('网络请求错误');
    return Promise.reject(err);
  }
});
Vue.prototype.url = ' http://192.168.1.223:8360'
Vue.prototype.code = 'cf259ae69d5142df937212c53f8dc3a6'
Vue.directive('title', {
  inserted: function (el, binding) {
    document.title = el.dataset.title
    document.getElementById('title').innerText = document.title
  }
})

new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})
